package com.ruiyian.bridge.project.controller;

import com.ruiyian.bridge.project.domain.DeviceTypeItem;
import com.ruiyian.bridge.project.service.DeviceTypeItemService;
import com.ruiyian.common.annotation.Log;
import com.ruiyian.common.core.controller.BaseController;
import com.ruiyian.common.core.domain.AjaxResult;
import com.ruiyian.common.core.page.TableDataInfo;
import com.ruiyian.common.enums.BusinessType;
import com.ruiyian.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 设备类型itemController
 *
 * @author ruiyian
 * @date 2022-01-21
 */
@RestController
@RequestMapping("/bridge/project/item")
public class DeviceTypeItemController extends BaseController
{
    @Autowired
    private DeviceTypeItemService tDeviceTypeItemService;


    /**
     * 查询传感器监测类型列表
     */
    @PreAuthorize("@ss.hasPermi('bridge:project:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceTypeItem deviceTypeItem)
    {
        startPage();
        List<DeviceTypeItem> list = tDeviceTypeItemService.selectTSensorTypeItemList(deviceTypeItem);
        return getDataTable(list);
    }


    /**
     * 查询所有数据
     */
    @PostMapping("/getList")
    public AjaxResult getList(@RequestBody DeviceTypeItem deviceTypeItem) {
        List<DeviceTypeItem> list = tDeviceTypeItemService.selectTSensorTypeItemListBySensorType(deviceTypeItem);
        return AjaxResult.success(list);
    }

    /**
     * 导出传感器监测类型列表
     */
    @PreAuthorize("@ss.hasPermi('bridge:project:item:export')")
    @Log(title = "传感器监测类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceTypeItem deviceTypeItem)
    {
        List<DeviceTypeItem> list = tDeviceTypeItemService.selectTSensorTypeItemList(deviceTypeItem);
        ExcelUtil<DeviceTypeItem> util = new ExcelUtil<DeviceTypeItem>(DeviceTypeItem.class);
        try {
            util.exportExcel(response, list, "传感器监测类型数据");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取传感器监测类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('bridge:project:item:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(tDeviceTypeItemService.selectTSensorTypeItemById(id));
    }

    /**
     * 新增传感器监测类型
     */
    @PreAuthorize("@ss.hasPermi('bridge:project:item:add')")
    @Log(title = "传感器监测类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceTypeItem deviceTypeItem)
    {
        return toAjax(tDeviceTypeItemService.insertTSensorTypeItem(deviceTypeItem));
    }

    /**
     * 修改传感器监测类型
     */
    @PreAuthorize("@ss.hasPermi('bridge:project:item:edit')")
    @Log(title = "传感器监测类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceTypeItem deviceTypeItem)
    {
        return toAjax(tDeviceTypeItemService.updateTSensorTypeItem(deviceTypeItem));
    }

    /**
     * 删除传感器监测类型
     */
    @PreAuthorize("@ss.hasPermi('bridge:project:item:remove')")
    @Log(title = "传感器监测类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(tDeviceTypeItemService.deleteTSensorTypeItemByIds(ids));
    }
}
